package com.wangt.drools;

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;

import java.io.*;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

@EnableDubbo
@SpringBootApplication
public class WangtDroolsApplication {
    /*public static void main(String[] args) {
        SpringApplication application = new SpringApplication(WangtDroolsApplication.class);
        application.setApplicationStartup(new BufferingApplicationStartup(2048));
        application.run(args);
        System.out.println("(♥◠‿◠)ﾉﾞ  设备与规则启动成功   ლ(´ڡ`ლ)ﾞ  ");
    }*/

    public static void main(String[] args) {
        try {
            Socket s = new Socket("127.0.0.1", 11000);
            //构建IO
            InputStream is = s.getInputStream();
            OutputStream os = s.getOutputStream();
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            Thread readThread = new Thread() {
                public void run() {
                    while (true) {
                        String msg = null;
                        try {
                            msg = br.readLine();
                            System.out.println(msg);
                            System.out.println("客户端接受消息为 " + msg);
                            bw.write("1234" + "\n");
                            bw.flush();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        System.out.println(msg);
                    }
                }
            };
            readThread.start();

        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
